<?php

namespace CMS;

class Request {
	public function get($key, $type = 'string') {
		if(!isset($_GET[$key]))
			return null;

		return $this->check($_GET[$key], $type);
	}

	public function post($key, $type = 'string') {
		if(!isset($_POST[$key]))
			return null;

		return $this->check($_POST[$key], $type);
	}

	private function check($value, $type) {
		if($type != 'array') {
			$value = (string)trim($value);
			if(!strlen($value) > 0)
				return null;
		}

		if($type == 'string')
			if(!is_string($value))
				return null;

		if($type == 'int')
			if(!is_numeric($value))
				return null;

		if($type == 'array')
			if(!is_array($value))
				return null;

		return $value;
	}
}